import {ServicePrefixEnum} from "@/enums/commonEnum";
import {RequestEnum} from "@/enums/httpEnum";
import {defHttp} from "@/utils/http/axios";
import type { AxiosRequestConfig } from 'axios';
export interface MenuVO {
  id: number
  name: string
  permission: string
  type: number
  sort: number
  parentId: number
  path: string
  icon: string
  component: string
  componentName?: string
  status: number
  visible: boolean
  keepAlive: boolean
  alwaysShow?: boolean
  createTime: Date
}

const MODULAR = 'system/menu'

export const Api = {
  GetSimpleMenusList: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/simple-list`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  getMenuList: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/list`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  GetMenu: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/get`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  CreateMenu: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/create`,
    method: RequestEnum.POST,
  } as AxiosRequestConfig,
  UpdateMenu: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/update`,
    method: RequestEnum.PUT,
  } as AxiosRequestConfig,
  deleteMenu: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/delete`,
    method: RequestEnum.DELETE,
  } as AxiosRequestConfig,

}


// 查询菜单（精简）列表
export const getSimpleMenusList = () => {
 return defHttp.request({ ...Api.GetSimpleMenusList })
}

// 查询菜单列表
export const getMenuList = (params) => {
  return defHttp.request({ ...Api.getMenuList, params })
}

// 获取菜单详情
export const getMenu = (id: number) => {
  let params = {id: id}
  return defHttp.request({ ...Api.GetMenu,params })
}

// 新增菜单
export const createMenu = (data: MenuVO) => {
  let params = {data: data}
  return defHttp.request({ ...Api.CreateMenu,params:params })
}

// 修改菜单
export const updateMenu = (data: MenuVO) => {
  let params = {data: data}
  return defHttp.request({ ...Api.UpdateMenu,params:params })
}

// 删除菜单
export const deleteMenu = (id: number) => {
  let params = {id: id}
  return  defHttp.request({ ...Api.deleteMenu,params })
}
